/*******************************************************************************
 * Copyright 2020 huanggefan.cn
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 ******************************************************************************/

package models

import (
	"database/sql"
)

type Question struct {
	UUID           string         `gorm:"not null; primaryKey; type:uuid; default:gen_random_uuid()"`
	Question       sql.NullString `gorm:"not null; type:text; uniqueIndex:uk_question"`
	Analysis       sql.NullString `gorm:"not null; type:text; default:''"`
	AnswerA        sql.NullString `gorm:"not null; type:text; default:''; uniqueIndex:uk_question"`
	AnswerB        sql.NullString `gorm:"not null; type:text; default:''; uniqueIndex:uk_question"`
	AnswerC        sql.NullString `gorm:"not null; type:text; default:''; uniqueIndex:uk_question"`
	AnswerD        sql.NullString `gorm:"not null; type:text; default:''; uniqueIndex:uk_question"`
	AnswerE        sql.NullString `gorm:"not null; type:text; default:''; uniqueIndex:uk_question"`
	AnswerF        sql.NullString `gorm:"not null; type:text; default:''; uniqueIndex:uk_question"`
	AnswerG        sql.NullString `gorm:"not null; type:text; default:''; uniqueIndex:uk_question"`
	AnswerH        sql.NullString `gorm:"not null; type:text; default:''; uniqueIndex:uk_question"`
	IsA            sql.NullBool   `gorm:"not null; type:bool; default:false; uniqueIndex:uk_question"`
	IsB            sql.NullBool   `gorm:"not null; type:bool; default:false; uniqueIndex:uk_question"`
	IsC            sql.NullBool   `gorm:"not null; type:bool; default:false; uniqueIndex:uk_question"`
	IsD            sql.NullBool   `gorm:"not null; type:bool; default:false; uniqueIndex:uk_question"`
	IsE            sql.NullBool   `gorm:"not null; type:bool; default:false; uniqueIndex:uk_question"`
	IsF            sql.NullBool   `gorm:"not null; type:bool; default:false; uniqueIndex:uk_question"`
	IsG            sql.NullBool   `gorm:"not null; type:bool; default:false; uniqueIndex:uk_question"`
	IsH            sql.NullBool   `gorm:"not null; type:bool; default:false; uniqueIndex:uk_question"`
	IsTrue         sql.NullBool   `gorm:"not null; type:bool; default:false; uniqueIndex:uk_question"`
	Type           sql.NullInt32  `gorm:"not null; type:integer; uniqueIndex:uk_question"`
	Level          sql.NullInt32  `gorm:"not null; type:integer; default:0"`
	AnswerCount    sql.NullInt32  `gorm:"not null; type:integer; default:0"`
	CorrectCount   sql.NullInt32  `gorm:"not null; type:integer; default:0"`
	ChapterUUID    sql.NullString `gorm:"not null; index:idx_question_chapterUUID; uniqueIndex:uk_question"`
	Chapter        Chapter        `gorm:"foreignKey:ChapterUUID; references:UUID; constraint:OnUpdate:CASCADE,OnDelete:CASCADE"`
	IsExamQuestion sql.NullBool   `gorm:"not null; type:bool; default:false"`
}

type QuestionAnswer struct {
	StudentID    int32    `gorm:"not null; index:idx_questionAnswer_studentID"`
	Student      User     `gorm:"foreignKey:StudentID; references:AccountID; constraint:OnUpdate:CASCADE,OnDelete:CASCADE"`
	QuestionUUID string   `gorm:"not null"`
	Question     Question `gorm:"foreignKey:QuestionUUID; references:UUID; constraint:OnUpdate:CASCADE,OnDelete:CASCADE"`
	UsedTime     int32    `gorm:"not null; integer"`
	IsCorrect    bool     `gorm:"not null; type:bool"`
}
